package com.mydemo.game.hireStage.random;

import com.mydemo.entity.Car;

import java.util.Random;

public class CarRandom {
    //无参函数,放回Car类
    // 存储所有可能的车型
    private static final String[] carModels = {"Sedan", "SUV", "MPV", "Hatchback", "Coupe"};
    // 存储所有可能的车辆品牌
    private static final String[] carBrands = {"丰田（Toyota）", "本田（Honda）", "福特（Ford）", "大众（Volkswagen）", "宝马（BMW）",
            "奔驰（Mercedes-Benz）", "奥迪（Audi）", "日产（Nissan）", "现代（Hyundai）", "起亚（Kia）",
            "别克（Buick）", "雪佛兰（Chevrolet）", "凯迪拉克（Cadillac）", "沃尔沃（Volvo）", "雷克萨斯（Lexus）",
            "路虎（Land Rover）", "捷豹（Jaguar）", "保时捷（Porsche）", "玛莎拉蒂（Maserati）", "法拉利（Ferrari）",
            "兰博基尼（Lamborghini）", "阿斯顿·马丁（Aston Martin）", "宾利（Bentley）", "劳斯莱斯（Rolls-Royce）",
            "Jeep", "斯柯达（Skoda）", "标致（Peugeot）", "雪铁龙（Citroen）", "马自达（Mazda）", "三菱（Mitsubishi）",
            "铃木（Suzuki）", "斯巴鲁（Subaru）", "五十铃（Isuzu）", "雷诺（Renault）", "菲亚特（Fiat）",
            "阿尔法·罗密欧（Alfa Romeo）", "克莱斯勒（Chrysler）", "道奇（Dodge）", "GMC", "林肯（Lincoln）",
            "讴歌（Acura）", "英菲尼迪（Infiniti）", "特斯拉（Tesla）", "比亚迪（BYD）", "吉利（Geely）",
            "长城（Great Wall）", "长安（Changan）", "奇瑞（Chery）", "传祺（Trumpchi）", "荣威（Roewe）",
            "名爵（MG）", "五菱（Wuling）", "东风（Dongfeng）", "北汽（BAIC）", "江淮（JAC）",
            "江铃（JMC）", "海马（Haima）", "众泰（Zotye）", "力帆（Lifan）", "东南（Soueast）",
            "金杯（Jinbei）", "中华（Brilliance）", "奔腾（Besturn）", "启辰（Venucia）", "观致（Qoros）"};
    // 存储所有可能的车辆具体型号
    private static final String[] carModelDetails = {"Camry", "CR-V", "Explorer", "Golf", "3 Series",
            "C-Class", "A4", "Altima", "Elantra", "K5",
            "Regal", "Malibu", "XT5", "XC60", "ES",
            "Range Rover", "F-Type", "911", "Ghibli", "488",
            "Huracan", "DB11", "Continental", "Ghost",
            "Wrangler", "Octavia", "308", "C5",
            "Mazda6", "Outlander", "Swift", "Forester",
            "D-Max", "Clio", "500", "Giulia", "Pacifica",
            "Charger", "Sierra", "Navigator", "MDX",
            "QX50", "Model 3", "Han", "Emgrand",
            "Haval H6", "CS75", "Tiggo 8", "GS4",
            "RX5", "ZS", "Hongguang", "AX7",
            "X35", "T70", "SR9", "820", "X40",
            "V7", "T90", "D60"};
    // 用于生成随机数的 Random 对象
    private static final Random random = new Random();

    // 生成随机车辆的方法
    public static Car generateRandomCar() {
        // 随机选择车型索引
        int modelIndex = random.nextInt(carModels.length);
        // 随机选择车辆品牌索引
        int brandIndex = random.nextInt(carBrands.length);
        // 随机选择车辆具体型号索引
        int detailIndex = random.nextInt(carModelDetails.length);
        // 根据车型确定座位数量
        int seatNum;
        String model = carModels[modelIndex];
        if (model.equals("Sedan") || model.equals("Coupe") || model.equals("Hatchback")) {
            seatNum = random.nextInt(5) + 2;
        } else if (model.equals("SUV")) {
            seatNum = random.nextInt(8) + 5;
        } else {
            seatNum = random.nextInt(12) + 7;
        }

        // 生成随机车牌，格式为省份简称+大写字母+5 位数字
        String carId = generateRandomCarId();
        int rentPrise;
        int price;
        String brand = carBrands[brandIndex];
        String modelDetail = carModelDetails[detailIndex];
        boolean isLuxuryCar = isLuxuryBrandAndModel(brand, modelDetail);
        if (isLuxuryCar) {
            rentPrise = random.nextInt(1000) + 500;
            price = random.nextInt(500) + 200;
        } else {
            rentPrise = random.nextInt(500);
            price = random.nextInt(200);
        }

        return new Car(model, brand, modelDetail, seatNum, carId, rentPrise, price);
    }

    // 判断车辆品牌和型号是否为豪华车的方法
    private static boolean isLuxuryBrandAndModel(String brand, String modelDetail) {
        return brand.contains("宝马") || brand.contains("奔驰") || brand.contains("奥迪") || brand.contains("保时捷") || brand.contains("玛莎拉蒂") || brand.contains("法拉利") || brand.contains("兰博基尼") || brand.contains("阿斯顿·马丁") || brand.contains("宾利") || brand.contains("劳斯莱斯")
                || (modelDetail.equals("911") || modelDetail.equals("Ghibli") || modelDetail.equals("488") || modelDetail.equals("Huracan") || modelDetail.equals("DB11") || modelDetail.equals("Continental") || modelDetail.equals("Ghost"));
    }

    // 生成随机车牌的方法
    private static String generateRandomCarId() {
        // 省份简称列表
        String[] provinceAbbreviations = {"京", "津", "沪", "渝", "冀", "豫", "云", "辽", "黑", "湘", "皖", "鲁", "新", "苏", "浙", "赣", "鄂", "桂", "甘", "晋", "蒙", "陕", "吉", "闽", "贵", "粤", "青", "藏", "川", "宁", "琼"};
        // 随机选择一个省份简称
        String provinceAbbreviation = provinceAbbreviations[random.nextInt(provinceAbbreviations.length)];
        // 随机生成一个大写字母
        char letter = (char) (random.nextInt(26) + 'A');
        // 生成 5 位数字
        StringBuilder numberBuilder = new StringBuilder();
        for (int i = 0; i < 5; i++) {
            numberBuilder.append(random.nextInt(10));
        }
        // 返回车牌字符串
        return provinceAbbreviation + letter + numberBuilder.toString();
    }

}
